<?php

namespace addons\member\user\controller;
use  \addons\member\model\SysFeedback;
/**
 * 反馈
 */
class Feedback extends \web\user\controller\AddonUserBase{
    public function index(){
        return $this->fetch(); 
    }
     /**
     * 反馈显示
     */
    public function loadList() {
        $m = new SysFeedback();
        $keyword = $this->_get('keyword');
        $filter = '1=1';
        if ($keyword != null) {
            $filter .= ' and (b.username like \'%' . $keyword . '%\' or b.phone  like \'%' . $keyword . '%\')';
        }
        $total = $m->getFeedbackTotal($filter);
        $rows = $m->getFeedbackList($this->getPageIndex(), $this->getPageSize(), $filter);
        return $this->toDataGrid($total, $rows);
    }
	/**
     * 客服回复
     */
    public function reply(){
    	$FeedbackModel = new SysFeedback();
    	if ($_POST) {
    		$id = input('id');
    		$data['reply_content'] = input('reply_content');
    		$data['update_time'] = NOW_DATETIME;
    		$data['is_reply'] = '1';
    		$a = $FeedbackModel->save($data,['id'=>$id]);
    		 if ($a){
                return $this->successData();
             }else{
                return $this->failData('回复失败');
            }
    	}else{
    		$id = intval($this->_get('id'));
            $this->assign('id',$id);
            $this->setLoadDataAction('loadData');
            $images = $FeedbackModel->getDetail($id, 'images')['images'];
            $arr_images = [];
            if($images != ''){
                $arr_images = explode(',', $images);
            }
            $this->assign('arr_images', $arr_images);
    		return $this->fetch();
    	}
    }
     public function loadData() {
        $id = $this->_get('id');
        $FeedbackModel = new SysFeedback();
        $content = $FeedbackModel->where('id',$id)->find();
        return $content;
    }
}
